package com.zhang.linkNode;

/**
 *2.单个环形链表
 * @param <E>
 */
public class SimpleAnnularNode<E> {

    class  ZKNode<E>{

        private ZKNode next;
        private E value;

        ZKNode(E value, ZKNode zkNode){
            this.value=value;
            this.next=zkNode;
        }
        ZKNode(E value)
        {
            this(value,null);
        }
    }

    private ZKNode head;
    private int size;

    SimpleAnnularNode()
    {
        //todo 需要注意循环链表头结点给值
        head=new ZKNode(null);
        head.next=head;
        size=0;
    }

    public int getSize()
    {
        return size;
    }

    /**
     * 显示数据
     * //todo 需要注意此循环
     */
    public void  view()
    {
        ZKNode zkNode=head.next;
        if (zkNode!=null)
        {
            while (zkNode!=head)
            {
                System.out.println(zkNode.value);
                zkNode=zkNode.next;
            }
        }
    }
    public void addFirst(E value) {
        if (value==null)
        {
            System.out.println("插入的数据为空");
            return;
        }
        ZKNode zkNode=new ZKNode(value);
        ZKNode head=this.head;
        zkNode.next=head.next;
        head.next=zkNode;
          size++;
    }


}
class Tset2 {
    public static void main(String[] a) {
        SimpleAnnularNode<String> doubleLink = new SimpleAnnularNode();
        doubleLink.addFirst("啊");
        doubleLink.addFirst("我");
        System.out.println(doubleLink.getSize());
        doubleLink.view();
        System.out.println("-----------");

    }
}
